package com.ygqh.baby.shiro;

import java.io.IOException;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.ygqh.baby.service.impl.DocumentConstant;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

import com.alibaba.fastjson.JSON;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.model.YgLoginModel;
import org.springframework.beans.factory.annotation.Autowired;

public class JsonFormAuthenticationFilter extends FormAuthenticationFilter {
	@Autowired
	private DocumentConstant documentConstant;

	@Override
	protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
		
		response.setCharacterEncoding("utf8");
		response.setContentType("text/html");
		String json=JSON.toJSONString(Message.loginError(new YgLoginModel("REDIRECT_LONGIN_PAGE", documentConstant.REDIRECT_LONGIN_PAGE)));
		
		response.getWriter().print(json);
	}
}
